﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using GovernmentOfficeProject.LevelDataAccessModel;
using GovernmentOfficeProject.SysTools;
using GovernmentOfficeProject.LevelDataAccess;
using System.Collections.Generic;

namespace GovernmentOfficeProject.LevelBusinessLogic
{
    /// <summary>
    /// 日程业务逻辑类
    /// </summary>
    public class BLL_CALENDAR
    {

        private static DAL_SME_SCHEDULE dalSchedule = null;
        private static DAL_COM_Sms_Ready dalSmsReady = null;
        private static DAL_USER_User dalUser = null;

        public BLL_CALENDAR()
        {
            if (dalSchedule == null) dalSchedule = new DAL_SME_SCHEDULE();
            if (dalSmsReady == null) dalSmsReady = new DAL_COM_Sms_Ready();
            if (dalUser == null) dalUser = new DAL_USER_User();
        }
        /// <summary>
        /// 根据用户ID,开始日期，结束日期 获得日程信息
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <returns></returns>
        public List<Entity_SME_Schedule> getScheduleListByUserIdAndDate(decimal userId, string startDate, string endDate,bool isLdCalendar)
        {

            return dalSchedule.getScheduleListByUserIdAndDate(userId, startDate, endDate, isLdCalendar);
        }

        /// <summary>
        /// 获得日程分页数据
       /// </summary>
       /// <param name="calendar">查询对象</param>
       /// <param name="isLdCalendar">是否为领导日程</param>
       /// <param name="currentPage">当前页</param>
       /// <param name="pageSize">每页显示条数</param>
       /// <returns></returns>
        public List<Entity_SME_Schedule> getSchedulePaginationList(Entity_SME_Schedule calendar, int currentPage, int pageSize)
        {
            return dalSchedule.getSchedulePaginationList(calendar, currentPage, pageSize);
        }

        /// <summary>
        /// 获得数据总数
        /// </summary>
        /// <param name="calendar"></param>
        /// <returns></returns>
        public int getAllCount(Entity_SME_Schedule calendar)
        {
            return dalSchedule.getAllCount(calendar);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Entity_SME_Schedule getScheduleById(decimal id)
        {
            Entity_SME_Schedule calendar = dalSchedule.getScheduleById(id);
            Entity_COM_Sms_Ready smsReady = new Entity_COM_Sms_Ready();
            smsReady.RdyAccessType = "SME_SCHEDULE";
            smsReady.RdyAccessValue = calendar.SceID;
            //获得日程提醒信息
            List<Entity_COM_Sms_Ready> smsReadyList = dalSmsReady.getSmsReadyListBysmsRdyEntity(smsReady);
            if (smsReadyList != null && smsReadyList.Count > 0)
            {
                smsReady = smsReadyList[0];
                calendar.IsSms = 1;
                calendar.SmsReady = smsReady;
            }
            //获得创建用户和修改用户详细信息
            calendar.CreateUser = dalUser.getUserByUserID(calendar.CreateUserId);
            calendar.ModifyUser = dalUser.getUserByUserID(calendar.ModifyUserId);

            return calendar;
        }



        /// <summary>
        /// 根据ID更新日程
        /// </summary>
        /// <param name="id"></param>
        /// <param name="calendar"></param>
        /// <returns></returns>
        public bool updateScheduleById(decimal id, Entity_SME_Schedule calendar)
        {

            return dalSchedule.updateScheduleById(id,calendar);
        }


        /// <summary>
        /// 保存日程
        /// </summary>
        /// <param name="calendar"></param>
        /// <returns></returns>
        public bool SaveSchedule(Entity_SME_Schedule calendar)
        {

            return dalSchedule.SaveSchedule(calendar);
        }


        /// <summary>
        /// 根据ID删除日程
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool deleteScheduleById(long id)
        {

            return dalSchedule.deleteScheduleById(id);
        }

        /// <summary>
        /// 获得自增ID
        /// 用于添加成功后获取ID
        /// </summary> 
        /// <returns></returns>
        public decimal getIdentCurrent()
        {
            return dalSchedule.getIdentCurrent();
        }

    }
}
